//
//  main.cpp
//  iniPraseDemo
//
//  Created by King.Sollyu on 14-8-7.
//  Copyright (c) 2014年 sollyu. All rights reserved.
//
//  Site: http://www.sollyu.com/ini-parse-class

#include <iostream>
#include "IniParser.h"

typedef struct STRUCT_TEST
{
private:
    char szName[15];
    char szLink[50];
    
public:
    STRUCT_TEST(){ memset(szName, '\0', sizeof(szName)); memset(szLink, '\0', sizeof(szLink)); }
    const std::string GetName() const { return szName; }
    const std::string GetLink() const { return szLink; }
    
    void SetName(const std::string& value ) { strncpy(szName, value.c_str(), sizeof(szName)); }
    void SetLink(const std::string& value ) { strncpy(szLink, value.c_str(), sizeof(szLink)); }
}STRUCT_TEST;

void LoadTest( IniParser* iniPrase )
{
    STRUCT_TEST struct_test_0;
    STRUCT_TEST struct_test_1;
    
    iniPrase->getStruct("Section_0", "中文", &struct_test_0, sizeof(STRUCT_TEST));
    iniPrase->getStruct("Section_1", "英文", &struct_test_1, sizeof(STRUCT_TEST));
    
    std::cout << struct_test_0.GetName() << "\t" << struct_test_0.GetLink() << std::endl;
    std::cout << struct_test_1.GetName() << "\t" << struct_test_1.GetLink() << std::endl;
}

void SaveTest( IniParser* iniPrase )
{
    STRUCT_TEST struct_test_0;
    struct_test_0.SetName("个人博客");
    struct_test_0.SetLink("http://www.sollyu.com/ini-parser-class");
    
    STRUCT_TEST struct_test_1;
    struct_test_1.SetName("Open Source");
    struct_test_1.SetLink("https://git.oschina.net/sollyu/IniParser.git");
    
    std::cout << sizeof(STRUCT_TEST) << std::endl;
    iniPrase->setStruct("Section_0", "中文", &struct_test_0, sizeof(STRUCT_TEST));
    iniPrase->setStruct("Section_1", "英文", &struct_test_1, sizeof(STRUCT_TEST));
    
    iniPrase->save();
}

void DeleTest( IniParser* iniPrase )
{
    iniPrase->delKey("Section_0", "中文");
//    iniPrase->delSection("Section_0");
    iniPrase->save();
}

int main(int argc, const char * argv[]) {
    // 显示程序运行的目录
    system("pwd");
    
    IniParser iniPrase;
    iniPrase.load("./test.ini");
    
    SaveTest(&iniPrase);
//    LoadTest(&iniPrase);
//    DeleTest(&iniPrase);
    
//    iniPrase.saveAs("./test.ini");
    
    
    return 0;
}
	